package com.kfm.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/context")
public class ServletContextServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("ServletContextServlet.doGet()");

        ServletContext servletContext = getServletContext();
        // 获取 ServletContext 对象
        System.out.println(servletContext);

        String contextPath = servletContext.getContextPath();
        System.out.println(contextPath);

        String realPath = servletContext.getRealPath("/lib");
        System.out.println(realPath);

    }
}
